using System;
using System.Collections;
using System.Collections.Generic;
namespace IcsSEMCtrl.Util
{
	public class StringTokenizer : IEnumerable<string>, IEnumerable
	{
		public const string DefaultDelimiters = " \t\n\r\f";
		private readonly string delims = " \t\n\r\f";
		private string[] tokens = null;
		private int index = 0;
		private string empty = string.Empty;
		public bool HasMoreTokens
		{
			get
			{
				return this.index < this.tokens.Length;
			}
		}
		public string NextToken
		{
			get
			{
				return this.tokens[this.index++];
			}
		}
		public int CountTokens
		{
			get
			{
				return this.tokens.Length - this.index;
			}
		}
		public int Count
		{
			get
			{
				return this.tokens.Length;
			}
		}
		public string this[int index]
		{
			get
			{
				return this.tokens[index];
			}
		}
		public string EmptyString
		{
			get
			{
				return this.empty;
			}
		}
		public StringTokenizer(string str)
		{
			this.Tokenize(str, false, false);
		}
		public StringTokenizer(string str, string delims)
		{
			if (delims != null)
			{
				this.delims = delims;
			}
			this.Tokenize(str, false, false);
		}
		public StringTokenizer(string str, params char[] delims)
		{
			if (delims != null)
			{
				this.delims = new string(delims);
			}
			this.Tokenize(str, false, false);
		}
		public StringTokenizer(string str, string delims, bool returnDelims)
		{
			if (delims != null)
			{
				this.delims = delims;
			}
			this.Tokenize(str, returnDelims, false);
		}
		public StringTokenizer(string str, string delims, bool returnDelims, bool returnEmpty)
		{
			if (delims != null)
			{
				this.delims = delims;
			}
			this.Tokenize(str, returnDelims, returnEmpty);
		}
		public StringTokenizer(string str, string delims, bool returnDelims, bool returnEmpty, string empty)
		{
			if (delims != null)
			{
				this.delims = delims;
			}
			this.empty = empty;
			this.Tokenize(str, returnDelims, returnEmpty);
		}
		private void Tokenize(string str, bool returnDelims, bool returnEmpty)
		{
			if (returnDelims)
			{
				this.tokens = str.Split(this.delims.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
				List<string> list = new List<string>(this.tokens.Length << 1);
				int i = str.IndexOfAny(this.delims.ToCharArray());
				int num = 0;
				int num2 = i - 1;
				if (i == 0)
				{
					do
					{
						list.Add(new string(str[i], 1));
						num2 = i++;
						i = str.IndexOfAny(this.delims.ToCharArray(), i);
						if (returnEmpty && i == num2 + 1)
						{
							list.Add(this.empty);
						}
					}
					while (i == num2 + 1);
				}
				while (i > -1)
				{
					list.Add(this.tokens[num++]);
					do
					{
						list.Add(new string(str[i], 1));
						num2 = i++;
						i = str.IndexOfAny(this.delims.ToCharArray(), i);
						if (returnEmpty && i == num2 + 1)
						{
							list.Add(this.empty);
						}
					}
					while (i == num2 + 1);
				}
				if (num < this.tokens.Length)
				{
					list.Add(this.tokens[num++]);
				}
				this.tokens = list.ToArray();
			}
			else
			{
				if (returnEmpty)
				{
					this.tokens = str.Split(this.delims.ToCharArray(), StringSplitOptions.None);
					if (this.empty != string.Empty)
					{
						for (int j = 0; j < this.tokens.Length; j++)
						{
							if (this.tokens[j] == string.Empty)
							{
								this.tokens[j] = this.empty;
							}
						}
					}
				}
				else
				{
                    this.tokens = str.Split(this.delims.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
				}
			}
		}
		public void Reset()
		{
			this.index = 0;
		}
		public bool hasMoreTokens()
		{
			return this.HasMoreTokens;
		}
		public string nextToken()
		{
			return this.NextToken;
		}
		public int countTokens()
		{
			return this.CountTokens;
		}
		public IEnumerator<string> GetEnumerator()
		{
			while (this.HasMoreTokens)
			{
				yield return this.NextToken;
			}
			yield break;
		}
		IEnumerator IEnumerable.GetEnumerator()
		{
			return this.GetEnumerator();
		}
	}
}
